package com.lkd.http.controller;

import com.lkd.entity.NodeEntity;
import com.lkd.entity.VendingMachineEntity;
import com.lkd.http.controller.vo.NodeReq;
import com.lkd.service.NodeService;
import com.lkd.vo.Pager;
import org.bouncycastle.cert.ocsp.Req;
import org.simpleframework.xml.Path;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/node")
public class NodeController {

   @Autowired
   private NodeService nodeService;

    /*
    * 点位分页查询
    * */
    @GetMapping("/search")
    public Pager<NodeEntity> search(
            @RequestParam(defaultValue = "1") Integer pageIndex,
            @RequestParam(defaultValue = "10") Integer pageSize,
            String name,
            Long regionId
    ){ //1. 接收参数
        //2.调用service
        Pager<NodeEntity> pager = nodeService.search(pageIndex, pageSize, name, regionId);
        //3.返回结果
        return pager;
    }



    /*
    * 点位详情
    * @param id
    * @return
    * */
   @GetMapping("/vmList/{id}")
   public List<VendingMachineEntity> vmList(@PathVariable("id") Long id){ //1. 接收参数
       //2.调用service
       List<VendingMachineEntity> list = nodeService.vmList(id);
       //3.返回结果
       return list;
   }

    /*
    * 点位新增
    *@param nodeReq
    * @return
    * */
    @PostMapping
    public Boolean saveNode(@RequestBody NodeReq nodeReq){//1.接收参数
        //2.调用并返回
        return nodeService.saveNode(nodeReq);
    }

    /*
    * 修改
    * @param id
    * @param nodeReq
    * @return
    * */
    @PutMapping("/{id}")
    public Boolean update(@PathVariable("id") Long id,@RequestBody NodeReq nodeReq){//1.接收参数
        //2. 调用并返回
        return nodeService.updateNode(id,nodeReq);
    }

    /*
    * 点位删除
    * @param Long id
    * */
   @DeleteMapping("/{id}")
    public Boolean deleteNode(@PathVariable("id") Long id){//1. 接收参数
       //2.调用并返回
       return nodeService.deleteNode(id);

   }

}